/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
Ext.define('Nothing.view.user.UserManage', {
    extend: 'Nothing.ux.panel.DataViewer',
    alias: 'widget.userMgt',

    requires: ['Ext.ux.form.field.ClearButton'],

    store: 'Users',

    items: [
        {
            name: 'username',
            xtype: 'textfield',
            operation: 'LK'
        },
        {
            name: 'enabled',
            xtype: 'combo',
            fieldType: 'B',
            store: [
                [1, '启用'],
                [0, '禁用']
            ],
            listConfig: {
                getInnerTpl: function () {
                    return '<div data-qtip="{field2}. {field1}">{field2} ({field1})</div>';
                }
            },
            queryMode: 'local'
        },
        {
            name: 'lockedTime',
            xtype: 'datefield',
            format: 'Y-m-d',
            fieldType: 'L'
        }
    ],

    columns: [
        {
            header: '用户名', dataIndex: 'username', flex: 1,
            editor: {
                xtype: 'textfield',
                operator: 'LK'
            },
            filter: { xtype: 'textfield', plugins: ['clearbutton'], emptyText: '输入查找内容' }   // 必须是对象
        },
        {
            header: '姓名', dataIndex: 'realname',
            editor: 'textfield',
            filter: { xtype: 'textfield' },
            flex: 1
        },
        {
            header: '角色',
            dataIndex: 'rolenames',
            sortable: false,
//            xtype: 'templatecolumn', // 两种形式都可以
            flex: 1,
//            tpl: '{rolenames}',   // 用了 template 的话 dirty 不会显示
            editor: {
                name: 'roleIds',
                xtype: 'combo',
                rawValueUpdateField: 'rolenames',
                displayField: 'name',
                valueField: 'id',
                editable: false,
                multiSelect: true,
                store: Ext.create('Nothing.store.Roles'),
                queryParam: 'a',
                allQuery: 'ss'
            },
            filter: { xtype: 'combo' }
        },
        /*
         {
         header: '用户名(真实姓名)', xtype: 'templatecolumn', tpl: '{username} <tpl if="realname">({realname})</tpl> '
         },
         */
        {
            header: '联系方式', dataIndex: 'phone', editor: 'textfield', flex: 1
        },
        {
            header: '电子邮箱', dataIndex: 'email', editor: 'textfield', flex: 1
        },
        {
            header: '状态', dataIndex: 'enabled', xtype: 'booleancolumn', trueText: '启用', falseText: '禁用', flex: 1,
            editor: {
                xtype: 'combo',
                store: [
                    [true, '启用'],
                    [false, '禁用']
                ]
            },
            filter: {
                xtype: 'combo',
                store: [
                    ['', '全部'],
                    [1, '启用'],
                    [0, '禁用']
                ],
                onChange: function() {
                    var combo = this,
                        value = combo.getSubmitValue();
                    if ('' === value) {
                        return;
                    }
                }
            }
        },
        {
            header: '锁定时间', dataIndex: 'lockedTime', xtype: 'datecolumn'/*, editor: { xtype: 'datefield', format: 'Y-m-d' }*/
        }/*,
         {
         header: '操作',
         menuDisabled: true,
         xtype: 'actioncolumn',
         flex: 1,
         items: [
         {
         text: 'Edit',
         iconCls: 'icon-add',
         handler: function (grid, rowIndex, colIndex) {
         var rec = grid.getStore().getAt(rowIndex);
         Ext.MessageBox.alert("Edit " + rec.get('name'));
         }
         },
         {
         iconCls: 'icon-delete',
         text: 'Delete',
         handler: function (grid, rowIndex, colIndex) {
         var rec = grid.getStore().getAt(rowIndex);
         Ext.MessageBox.alert("Terminate " + rec.get('name'));
         }
         }
         ]
         }
         */
    ]
});
